package com.cy.cdas.controller;

import com.cy.cdas.entity.User;
import com.cy.cdas.service.UserService;
import com.cy.cdas.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    //增
    @PostMapping("/add")
    public ResultData add(@RequestBody User user) {
        System.out.println("进入controller");
        return userService.add(user);
    }

    //删
    @DeleteMapping("/delete")
    public ResultData delete(@RequestBody List<Integer> ids) {
        return userService.delete(ids);
    }
    //改
    @PutMapping("/update")
    public ResultData update(@RequestBody User user) {
        return userService.update(user);
    }
    //查-所有
    @GetMapping("/getAllUsers")
    public ResultData getAllUsers() {
        return userService.getAllUsers();
    }
    //查-id
    @GetMapping("/getOne")
    public ResultData getOne(@RequestParam int id) {
        return userService.getOne(id);
    }
}
